const state = {
  token: ''
} 
const mutations = {
  setToken(state, token) {
    state.token = token
  }
}
const actions = {
  async wxLogin(store) {
    // 拿到用户信息
    const [errProfile, resProfile] = await uni.getUserProfile({desc: '为您提供更好的服务'})
    console.log(resProfile);
    // 拿到微信临时验证code
    const [errCode, resCode] = await uni.login()
    console.log(resCode);
    // 换取 token
    const {message} = await uni.$u.post('/users/wxlogin', {
      encryptedData: resProfile.encryptedData,
      iv: resProfile.iv,
      rawData: resProfile.rawData,
      signature: resProfile.signature,
      code: resCode.code
    })
    console.log(message.token);
    store.commit('setToken', message.token)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}